{layout name="layout" /}
<h3>快递100</h3>
<br>
<h4>控制器代码</h4>
<textarea readonly style="width: 80%;height: 300px;">
    //快递100
    public function kuaiDi100()
    {
        //$postcom 为快递公司代码，具体代码请去官网查看
        //$getNu 快递单号
        $postcom = "shentong";
        $getNu = "";
        $kuaidi100 = new \demo\Kuaidi100();
        $data = $kuaidi100->run($postcom,$getNu);
//        echo "<pre>";
//        var_dump($data);
        return $data;
    }
</textarea>
<h3 style="color: red;">extend/demo/Kuaidi100.php</h3>
<textarea readonly style="width: 80%;height: 500px;">
namespace Demo;
header("content-type:text/html;charset=utf-8");
class Kuaidi100
{
    public $kuaidi100key = 'xxxxxx'; //快递100的key
    //$postcom 为快递公司代码，具体代码请去官网查看
    //$getNu 快递单号
    public function run($postcom,$getNu){
        $postcom = $this->getcom($postcom);
        $url="http://api.kuaidi100.com/api?id=$this->kuaidi100key&com=$postcom&nu=$getNu&show=0&muti=1&order=desc";
        $curl = curl_init();
        curl_setopt ($curl, CURLOPT_URL, $url);
        curl_setopt ($curl, CURLOPT_HEADER,0);
        curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
        curl_setopt ($curl, CURLOPT_TIMEOUT,5);
        $get_content = curl_exec($curl);
        curl_close ($curl);
        $express = json_decode($get_content, true);
        return $express;
    }
    public function getcom($getcom){
        switch ($getcom){
            case "EMS"://快递公司名称
                $postcom = 'ems';//快递公司代码
                break;
            case "中国邮政":
                $postcom = 'ems';
                break;
            case "申通快递":
                $postcom = 'shentong';
                break;
            case "圆通速递":
                $postcom = 'yuantong';
                break;
            case "顺丰速运":
                $postcom = 'shunfeng';
                break;
            case "天天快递":
                $postcom = 'tiantian';
                break;
            case "韵达快递":
                $postcom = 'yunda';
                break;
            case "中通速递":
                $postcom = 'zhongtong';
                break;
            case "龙邦物流":
                $postcom = 'longbanwuliu';
                break;
            case "宅急送":
                $postcom = 'zhaijisong';
                break;
            case "全一快递":
                $postcom = 'quanyikuaidi';
                break;
            case "汇通速递":
                $postcom = 'huitongkuaidi';
                break;
            case "民航快递":
                $postcom = 'minghangkuaidi';
                break;
            case "亚风速递":
                $postcom = 'yafengsudi';
                break;
            case "快捷速递":
                $postcom = 'kuaijiesudi';
                break;
            case "华宇物流":
                $postcom = 'tiandihuayu';
                break;
            case "中铁快运":
                $postcom = 'zhongtiewuliu';
                break;
            case "FedEx":
                $postcom = 'fedex';
                break;
            case "UPS":
                $postcom = 'ups';
                break;
            case "DHL":
                $postcom = 'dhl';
                break;
            case "百世快递":
                $postcom = 'baishiwuliu';
                break;
            default:
                $postcom = $getcom;
        }
        return $postcom;
    }
}

</textarea>